Skip to content

feat(playground): support explicit source types - #29638

Merged
Dunqing merged 1 commit into
mainfrom
claude/playground-source-type-binding
Nov 16, 2026
Merged

Dunqing merged 1 commit into
mainfrom
claude/playground-source-type-binding

Conversation

@Dunqing

@Dunqing Dunqing commented Nov 16, 2026

Copy link
Copy Markdown
Member

The playground binding cannot override source type, so TSX without import/export syntax emits require() helpers. Its public declarations also lack sourceType, blocking type-checking in oxc-project/playground#488.

Expose the parser's script, module, commonjs, and unambiguous modes through oxc_napi::get_source_type. Preserve extension-based language selection and inference when the option is omitted. Copy the generated WASI declarations to the public index.d.ts during binding patching.

Example

Input (playground for this input and configuration):

class A { #a = 0; }

Both binding builds use extension: "tsx", sourceType: "module", and transformer target es2015, with npm runtime helpers. The playground link contains the same run, parser, and transformer options; the deployed binding cannot demonstrate the new sourceType option until updated.

Before output (parent e4703b1848):

var _classPrivateFieldInitSpec = require("@oxc-project/runtime/helpers/classPrivateFieldInitSpec");
var _a = /* @__PURE__ */ new WeakMap();
class A {
	constructor() {
		_classPrivateFieldInitSpec(this, _a, 0);
	}
}

After output:

import _classPrivateFieldInitSpec from "@oxc-project/runtime/helpers/classPrivateFieldInitSpec";
var _a = /* @__PURE__ */ new WeakMap();
class A {
	constructor() {
		_classPrivateFieldInitSpec(this, _a, 0);
	}
}

The explicit Module mode now emits an ESM helper import. Both runs have no diagnostics and produce identical serialized source maps.

Verified the WASM development build on Rust 1.100.0; temporary Node/WASI assertions for all four modes, omitted-option inference, CommonJS top-level return, JavaScript strictness, TSX parsing, and source-map content; just lint -p oxc_playground_napi; Rust/script formatting and script lint. Playground vue-tsc reproduces exactly four sourceType errors with the parent's declarations and passes with the newly generated declarations. No persistent playground tests added.

AI assistance: implementation and verification were prepared with an AI coding assistant.

Expose the parser's script, module, commonjs, and unambiguous modes in the
playground binding using the shared get_source_type resolver. Preserve
extension-based inference when sourceType is omitted.

Copy generated WASI declarations to the public index.d.ts during patching
so playground consumers can type-check the new option.
@Dunqing
Dunqing merged commit eb817bb into main Nov 16, 2026
31 checks passed
@Dunqing
Dunqing deleted the claude/playground-source-type-binding branch November 16, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant